package com.ls.thread.ch04.demo01;


/**
 * implements Runable 常用
 * extends Thread 
 * @author My
 *
 */
public class TicketRunnable implements Runnable {

	
	private int ticket=10;
	
	private boolean flag=true;
	@SuppressWarnings("static-access")
	@Override
	public void run() {
		while(flag){
			
			
			
			synchronized(this){
				
				if(ticket>0){
					
					try {
						Thread.currentThread().sleep(100);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println(Thread.currentThread().getName()+"买票"+ticket);
					ticket=ticket-1;
				}else{
					flag=false;
				}
				
			}
		}
		
		
	}

}
